package com.newsmanagement.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;


public class Base64ImageUtil {
	
	public static void main(String[] args) throws IOException {
		// 测试从Base64编码转换为图片文件
		String strImg = "";
		
		Base64ImageUtil.GenerateImage(strImg.split("base64,")[1], "E://wangyc1.jpeg");
		Map<String ,Object> map = Base64ImageUtil.GenerateImageComplete(strImg, "E://thui/");
		if(null != map && (boolean)map.get("check")){
			System.out.println(map.get("object"));
		}
		
		// 测试从图片文件转换为Base64编码
		//Base64ImageUtil.GetImageStr("D:\\wangyc.jpg");
	}

	/**
	 * 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
	 * @param imgFilePath
	 * @return
	 */
	public static String GetImageStr(String imgFilePath) {
		byte[] data = null;

		// 读取图片字节数组
		try {
			InputStream in = new FileInputStream(imgFilePath);
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		// 对字节数组Base64编码
		BASE64Encoder encoder = new BASE64Encoder();
		// 返回Base64编码过的字节数组字符串
		return encoder.encode(data);
	}

	/**
	 * 对字节数组字符串进行Base64解码并生成图片:完整base64
	 * eg：
	 * @param imgStr
	 * @param imgFilePath:以“/”結尾
	 * @return
	 * @throws IOException
	 */
	public static Map<String ,Object> GenerateImageComplete(String imgStr, String imgFilePath) throws IOException {
		Map<String ,Object> map = new HashMap<String ,Object>();
		map.put("check", false);
		map.put("object", null);
		map.put("info", "");
		// 图像数据为空
		if (imgStr == null){
			map.put("info", "图像数据为空!");
			return map;
		}
		
		//文件夾創建
		CheckAndChangeUtil.getFile(imgFilePath, false);
		
		String fileType = ".jpg";
		if(imgStr.toLowerCase().contains("jpeg")){
			fileType = ".jpeg";
		}else if(imgStr.toLowerCase().contains("png")){
			fileType = ".png";
		}
		
		imgStr = imgStr.split("base64,")[1];
		
		imgFilePath = imgFilePath + System.currentTimeMillis() + fileType;
		
		boolean bl = GenerateImage(imgStr ,imgFilePath);
		map.put("check", bl);
		if(bl){
			map.put("object", imgFilePath);
		}
		return map;
	}
	
	/**
	 * 对字节数组字符串进行Base64解码并生成图片
	 * @param imgStr:只是圖片z數據
	 * eg：/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wgARCACbAQMDASIAAhEBAxEB/8QAGwAAAgMBAQEAAAAAAAAAAAAABAUCAwYBAAf/xAAaAQADAQEBAQAAAAAAAAAAAAABAgMABAUG/9oADAMBAAIQAxAAAAGbSojxu4uxdblM9AorV6/rDkPUEcjFStTl1ZC9FZJdLLV7lQNkC6yKLxIMGJmcU4b7ql3ueEbqnT3R6euZ0lvahj4HxAPaWXz3pUsPK7zcTyt9TpvZZiUa950TUp2aodxFq8qblTDmZlh1cDRIF6c1URFfXK+C2Yj6R8u3G5nq9iu6eJYnXq3o3sTwS2n9mPNvor1K681VClmuFwLbJtSILAUOx0OYs6OQ5S6S81C6eLDVhQQI+GIDtpoVh2vrhq4ETrn4pPb4XeRg57Gyc8ym0wncuNC+h+L/ADr30D2LJlTb54RJXaWlqvRzrHU25w/Z0OJBW0amlc0tAoNWycwQyLYGfvY0RLrZhrY3GY9RAzj30L57vBJ3QGPykYewGuZRHn1St9T4bVy7KRTqXKdarETtbRxqD1VldFqGvOxuZ2GQshxS4uDMuSrVRa5RxvqspV6LarKLUMQLQWbXF6GsjRzlnBQQNyqo0Slg110Hs74r9hsqs0kyhsn5+hUE0FqaqYX1Tl5VEG0OfbZvqkIQF2dGhYFqi6NXYvdT6kNC3llFGFdGOoT0KszaQ8y5HD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0kuBny/zHY9aur8EQclev5IGyDWTeYGGKgKAnbIVgu6vqOEnS4Dh6Ae5QYrCsM790B9y470Dq/FcPJuZpMUA/r/ALBcg+R9OpjiObD+GUq2Gy/3GRqnqKvOPcfmAQUC8ISbILzOpmHccbGpmpTIMI9kDgwcpaL3x2RQ+7jO09Jh/wBwQgK20vsZa1HvlzDI/BxOGusBEUbnEFg4OKyPzKgndGh7lbG225Hr3q4chAKhmDjebPzORNQD/uViVTqYbtgrGcV2dt4gsfUc/UYsGMl8e1hbUfERGNvJGHMqvOYRdxb3+cpDPgs/hFKf8hO8+sx+vbkfpr7xKSh9xGmAwIEpiLSzbo+yNr8jnIfExoRxQKjdbXVzafyBWiRqnAFHzHHJNoCHk5lERdrw+OpgZOP9RmtA3DvLVwELKjTioTL1Hn5H7iaVjrRkK/cNrXez7B/Eqx5Tovz3KFDi6Dj/ALKGWN3Q8lYfUuyAWV35iZm5lQxUkyiQF5cXomK40C49f4yAtxKflMpgs4OUZ3rgxML/ABoWdojL0i1OcxaU69wUDuLBFaKD1GbyzGyFJnGzu86h1JbZXmKXpEaJTjJEvy05dzDy4yB60/MItIArR2H4iBPBBfYLfuEKCLVTtXLEysmnqIhKfSXJLbWHHHManPMvNunE/ImaN0ymXiHbf+T/AAf4IBKUcEvDL82O/Mfman//2Q==
	 * @param imgStr
	 * @param imgFilePath
	 * @return boolean
	 * @throws IOException
	 */
	public static boolean GenerateImage(String imgStr, String imgFilePath) throws IOException {
		// 图像数据为空
		if (imgStr == null){
			return false;
		}
		BASE64Decoder decoder = new BASE64Decoder();
		// Base64解码
		byte[] bytes = decoder.decodeBuffer(imgStr);
		for (int i = 0; i < bytes.length; ++i) {
			// 调整异常数据
			if (bytes[i] < 0) {
				bytes[i] += 256;
			}
		}
		// 生成jpeg图片
		OutputStream out = new FileOutputStream(imgFilePath);
		out.write(bytes);
		out.flush();
		out.close();
		return true;
	}
}